package com.springboot.others;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

/**
 * @Author: TongRui乀
 * @Date: 2020-08-27 18:59
 * @description：
 */
@Slf4j
public class FileCopy {

    private String root = "D:\\资料\\桌面\\08-深入拆解Tomcat & Jetty";

    @Test
    public void test() {

        String childPath = root + "\\深入拆解Tomcat&Jetty(更新中)";

        copy(childPath);

    }

    private void copy(String childPath) {

        File child = new File(childPath);

        for (File file : child.listFiles()) {

            if(file.isDirectory()){
                copy(file.getAbsolutePath());
            }else {
                if(file.getName().endsWith(".pdf")){
                    File dest = new File(root + "\\" + file.getName());
                    try {
                        FileUtils.copyFile(file, dest);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

}
